//
//  HUGroupTableController.m
//  testMyPicturePicker
//
//  Created by Nova on 14-10-6.
//  Copyright (c) 2014年 huhuTec. All rights reserved.
//

#import "HUGroupTableController.h"
#import "HUGroupViewModel.h"
#import "HUGroupTableViewCell.h"
#import "HUGroupViewModel.h"
@interface HUGroupTableController()
@property(nonatomic,strong) NSArray* dataSource;
@property(nonatomic,strong) HUGroupViewModel* viewModel;
@end
@implementation HUGroupTableController
-(id)initWithTableView:(UITableView*)tableView
{

    self=[super init];
    if(self)
    {
        [tableView registerNib:[UINib nibWithNibName:@"HUGroupTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];
        tableView.dataSource=self;
        tableView.delegate=self;
        UITableViewCell* temp=[[[UINib nibWithNibName:@"HUGroupTableViewCell" bundle:nil] instantiateWithOwner:nil options:nil] firstObject];
        tableView.rowHeight=temp.frame.size.height;
        self.viewModel=[[HUGroupViewModel alloc] init];
        [[self.viewModel getGroupData] subscribeNext:^(NSArray* arr){
            self.dataSource=arr;
            [tableView reloadData];
        }];
        return self;
    }
    else
        return nil;

}

+(instancetype)BindTableViewController:(UITableView*)tableView
{
    return [[HUGroupTableController alloc] initWithTableView:tableView];
}


-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    HUGroupTableViewCell* cell=[tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    [cell BindViewModel:[self.dataSource objectAtIndex:indexPath.row]];
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    //cell.viewModel=[self.dataSource objectAtIndex:indexPath.row];
    return cell;
}

#pragma mark - UITableView Datasource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataSource.count;
}




#pragma mark - UITableView Delegate methods

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}
@end
